<?php

//include_once "../checkAuth.php";
//include_once "/CommonClass/errorcode.php";

function checkWorkersUpcomingShifts($userAuthName, $userAuthPassHash, $startDate, $userName){
	$err = new ErrorCode();
	$output = array();
	$shifts = array();
	if(checkAuthentication($userAuthName, $userAuthPassHash)){
		$link = mysqli_connect("localhost", "root", "", "paradigmshift_dev");

		if(mysqli_connect_errno()){
			$output[0] = $err::failRead;
		} else {
			$query = "SELECT roles.roleID, roles.roleName, dates.dateID, dates.datestamp, employees.empID, roledate.startTime, roledate.endTime, roledate.shiftStatus
					FROM employees left join (dates, roledate, account, roles)
					ON roledate.empID = employees.empID
					AND dates.dateID = roledate.dateID
					AND account.empID = employees.empID
					AND roles.roleID = roledate.roleID
					WHERE dates.datestamp >= '". $startDate ."'
							AND account.accName = '". $userName ."' ;";
			if ($result = mysqli_query($link, $query))
			{
				while($row = $result->fetch_assoc()){
					$shifts[] = array(
							"roleID" => $row["roleID"],
							"roleName" => $row["roleName"],
							"dateID" => $row["dateID"],
							"datestamp" => $row["datestamp"],
							"empID" => $row["empID"],
							"startTime" => $row["startTime"],
							"endTime" => $row["endTime"],
							"shiftStatus" => $row["shiftStatus"]
					);
				}
				$output[0] = $err::successRead;
				$output[1] = $shifts;
			}
			else
			{
				$output[0] = $err::failRead;
			}
			mysqli_close($link);
		}
	} else {
		$output[0] = $err::failRead;
	}
	return $output;
}
?>
